package single;

/**
 * @author 帅小伙
 * @date 2022/1/8
 * @description
 */
public class SingleMode {

    private SingleMode() {
    }

    ;

    /*
    懒汉式: 加上 synchronized   保证线程安全 只创建一个对象
    private static  SingleMode single;
    public static synchronized SingleMode getInstance (){
        if(single==null){
            single = new SingleMode();
        }
        return single;
    }*/



   /*
    饿汉式l
    private static  SingleMode single = new SingleMode();
    public static SingleMode getInstance(){
        return single;
    }*/


    // 双重检查
    private volatile static SingleMode single;
    public static SingleMode getInstance() {
        if(single == null){
            synchronized(SingleMode.class){
                if(single == null){
                    single = new SingleMode();
                }
            }
        }
        return single;
    }

}